/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.core.persistence.dao.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import com.teknei.acabus.PersistenceException;
import com.teknei.acabus.core.entities.NavigationChildRole;
import com.teknei.acabus.core.entities.NavigationParentRole;
import com.teknei.acabus.core.persistence.dao.NavigationRolesDAO;

/**
 * Session Bean implementation class NavigationRolesDAOBean
 * @author Jorge Amaro
 * @since 1.0
 * @version 1.0
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class NavigationRolesDAOBean implements NavigationRolesDAO {

	@PersistenceContext
	EntityManager em;
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.persistence.dao.NavigationRolesDAO#findNavigationParentRoles()
	 */
	@Override
	public List<NavigationParentRole> findNavigationParentRoles() throws PersistenceException{
		try{
			TypedQuery<NavigationParentRole> query = em.createNamedQuery("NavigationParentRole.findAll", NavigationParentRole.class);
			List<NavigationParentRole> list = query.getResultList();
			return list;
		}catch(Exception e){
			throw new PersistenceException("Error in findNavigationParentRoles:"+e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.persistence.dao.NavigationRolesDAO#findNavigationChildRoles()
	 */
	@Override
	public List<NavigationChildRole> findNavigationChildRoles() throws PersistenceException{
		try{
			TypedQuery<NavigationChildRole> query = em.createNamedQuery("NavigationChildRole.findAll", NavigationChildRole.class);
			List<NavigationChildRole> list = query.getResultList();
			return list;
		}catch(Exception e){
			throw new PersistenceException("Error in findNavigationChildRoles:"+e.getMessage(), e);
		}
	}
	
}
